function Entry(entry, commentsVisibility) {
	//fields
	var entryData = entry;
	var $component = EntryTemplate.normal();
	
	//Constructor
	create();
	
	//interface
	this.getComponent = function() {
		return $component;
	};
	
	//private functions
	function create() {
		Entries.loadEntry($component, entryData);
		
		setExtenderState();
		setCommentsVisibility(commentsVisibility);
		appendCommentCreator();
		attachListeners();
		successEffect();
	}
	
	function successEffect() {
		$component.effect("highlight", { color: "#ffff99" }, 500);
	}
	
	function failEffect() {
		$component.effect("highlight", { color: "#ff0000" }, 1000);
	}
	
	function refreshEntryData(entryID) {
		var refreshedEntry = null;
		var url = {
				type: "Entries",
				method: "Index/"+entryID,
		};
		var success = function(entry) {
			refreshedEntry = entry;
		};
		var error = function(e) {
			failEffect();
			console.log("error");
			console.log(e);
		};
		
		var params = {
				url: url,
				success: success,
				error: error,
				sync: true
		};
		
		Request.send(params);
		
		return refreshedEntry;
	};
	
	function setExtenderState() {
		if($component.find(".entry_body_extend").text().length > 0) {
			$component.find(".entry_body_expander").show();
		} else {
			$component.find(".entry_body_expander").hide();
		}
		
		$component.find(".entry_body_extend").hide();
	};
	
	function setCommentsVisibility(commentsVisibility) {
		$component.find(".comments").toggle(commentsVisibility);
	};

	function toggleCommentsVisibility() {
		$component.find(".comments").toggle({
			duration: 400,
			effect: "blind"
		});
	};
	
	function expandEntryBody() {
		$component.find(".entry_body_expander").hide();
		$component.find(".entry_body_extend").show('blind', 300);
	};
	
	function voteUp() {
		var url = {
				type: "Entries",
				method: "Vote/entry/"+entryData.id,
				param: "userkey," + UserLogon.getUserKey()
		};
		var success = function(voteResult) {
			successEffect();
		};
		var error = function(e) {
			failEffect();
			console.log("error");
			console.log(e);
			
			if(e && e.error && e.error.code) {
				if(e.error.code === 81) {
					$component.fadeOut();
				}
			}
		};
		
		var params = {
				url: url,
				success: success,
				error: error,
				sync: true
		};
		
		Request.send(params);
		
		var commentsVisibility = $component.find(".comments").is(":visible");
		
		var refreshedEntry = refreshEntryData(entryData.id);
		Entries.loadEntry($component, refreshedEntry);
		setCommentsVisibility(commentsVisibility);
		
		entryData = refreshedEntry;
		
		return false;
	}
	
	function appendCommentCreator($component) {
		//TODO doczepia komponent dodajacy komentarze
	}
	
	function attachListeners() {
		attachExpandEntryBodyListener();
		attachToggleCommentsVisibilityListener();
		attachVoteUpListener();
		attachVoteDownListener();
		attachRefreshListener();
		attachAnswerListener();
		//TODO dopisac pozostale listenery...
	};
	
	function attachExpandEntryBodyListener() {
		$component.find(".entry_body_expander").click( function() {
				expandEntryBody();
			});
	};
	function attachToggleCommentsVisibilityListener() {
		$component.click(function(){
			toggleCommentsVisibility($component);
		});
	};
	
	function attachVoteUpListener() {
		$component.find(".entry_vote").click(function(){
			voteUp();
			$(this).hide();
			$(".entry_unvote").show();
			
			return false;
		});
	};
	function attachVoteDownListener() {
		$component.find(".entry_unvote").click(function(){
			voteDown();
			$(this).hide();
			$(".entry_vote").show();
			
			return false;
		});
	};
	function attachRefreshListener() {};
	function attachAnswerListener() {};
};

function EntryPreview(entry) {//TODO
	//Constructor
	create(entry);
	
	//fields
	
	//interface
	this.getComponent = function() {
		return null;//zwroc wypelniony, dzialajacy komponent
	};
	
	//private functions
	function create(entry) {
		//pobierz odpowiedni template (small)
		//wypelnij go danymi
		//podczep listenery
	}
};